﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
//using Telerik.Reporting;
//using Telerik.Reporting.Charting;
//using Telerik.Reporting.Drawing;

namespace MLY.Reports
{
    public partial class advancedRptParams : MLY.Bll.BasePage
    {
        private MLY.Bll.ReportInfo repInfo;

        protected void Page_Load(object sender, EventArgs e)
        {

            #region oldCrystalReportsCode
            //errLbl.Visible = false;
            //lblErr.Visible = false;
            //divCriteria.Visible = false;
            //divCriteriaFill.Visible = false;
            //divWoQuantitiesDateColumns.Visible = false;
            //if (int.Parse(ddlReports.SelectedValue) == 1)//rptOnTimeDelivary.rpt
            //{
            //    divOTD.Visible = true;
            //    divCriteria.Visible = false;
            //    lblErr.Visible = false;
            //    divCriteriaFill.Visible = false;
            //    divWoQuantitiesDateColumns.Visible = false;
            //    // LoadOrgs();
            //}
            //else if (int.Parse(ddlReports.SelectedValue) == 3)//rptAvgWoDuration.rpt
            //{
            //    divOTD.Visible = false;
            //    lblErr.Visible = false;
            //    divCriteria.Visible = true;
            //    divCriteriaFill.Visible = true;
            //    divWoQuantitiesDateColumns.Visible = false;
            //}
            //else if (int.Parse(ddlReports.SelectedValue) == 4)//rptQuantityPerMonth.rpt
            //{
            //    ////divWoQuantitiesDateColumns.Visible = true;
            //    //divWoQuantitiesDateColumns.Visible = false;
            //    divOTD.Visible = true;
            //    divCriteria.Visible = false;
            //    lblErr.Visible = false;
            //    divCriteriaFill.Visible = false;
            //    divWoQuantitiesDateColumns.Visible = false;
            //}
            //else if (int.Parse(ddlReports.SelectedValue) == 5)//Inventory Balance
            //{
            //    ////divWoQuantitiesDateColumns.Visible = true;
            //    //divWoQuantitiesDateColumns.Visible = false;
            //    divOTD.Visible = true;
            //    divCriteria.Visible = false;
            //    lblErr.Visible = false;
            //    divCriteriaFill.Visible = false;
            //    divWoQuantitiesDateColumns.Visible = false;
            //}
            //else if (int.Parse(ddlReports.SelectedValue) == 6)//Graph Invenory Balance
            //{
            //    ////divWoQuantitiesDateColumns.Visible = true;
            //    //divWoQuantitiesDateColumns.Visible = false;
            //    divOTD.Visible = true;
            //    divCriteria.Visible = false;
            //    lblErr.Visible = false;
            //    divCriteriaFill.Visible = false;
            //    divWoQuantitiesDateColumns.Visible = false;
            //}
            //else
            //{
            //    divWoQuantitiesDateColumns.Visible = false;
            //    divOTD.Visible = false;
            //    lblErr.Visible = false;
            //    divCriteria.Visible = false;
            //    divCriteriaFill.Visible = false;
            //}

            #endregion

            //if (SessParam.OrganizationId != 25 && SessParam.OrganizationId != 46)
            //{
            //    //ExceptionsReportHyperlink.Visible = false;
            //    //ApprovedMaterialsReportHyperlink.Visible = false;
            //    //TPTRawDataHyperlink.Visible = false;
            //    //DataFlowReportLink.Visible = false;
            //    //EceptionsNoWithoutActualLink.Visible = false;
                
            //}
            //else
            //{
            //    ExceptionsReportHyperlink.Text = Dictionary.Translate("advancedRptPrams.ExceptionsReport");
            //    ApprovedMaterialsReportHyperlink.Text = Dictionary.Translate("advancedRptPrams.ApprovedMaterialsReport");
            //    TPTRawDataHyperlink.Text = Dictionary.Translate("advancedRptPrams.TPTRawDataReport");
            //}
            if (SessParam.OrganizationId == 25 || SessParam.OrganizationId == 46)
            {
                DataFlowReportLink.NavigateUrl = "~/Reports/AdvReportsViewer.aspx?ReportName=StepTimeDeviationSpecial";
                ExceptionsReportHyperlink.Text = Dictionary.Translate("advancedRptPrams.ExceptionsReport");
                TPTRawDataHyperlink.Text = Dictionary.Translate("advancedRptPrams.TPTRawDataReport");
                
            }
            else
            {
                ExceptionsReportHyperlink.Visible = false;
                TPTRawDataHyperlink.Visible = false;
                ApprovedMaterialsReportHyperlink.Visible = false;
            }

        }

        //protected void btnSubmit_OnClick(object sender, EventArgs e)
        //{
        //    repInfo = new MLY.Bll.ReportInfo();
        //    repInfo.ReportType = 1000 + int.Parse(ddlReports.SelectedValue);
        //    repInfo.OrganizationId = (int)Session["OrganizationId"];
        //    switch (repInfo.ReportType)
        //    {
        //        case 1001: //OTD Report
        //            repInfo.SelectedOrganizationId = int.Parse(ddlOrgs.SelectedValue);
        //            repInfo.DateColumn = ddlDateCriteriaField.SelectedItem.Text;
        //            repInfo.DateFrom = Utils.ParseDate(txtOTDDateStart.Text);
        //            repInfo.DateTill = Utils.ParseDate(txtOTDDateEnd.Text);
        //            break;
        //        case 1003: //average Work Orders Duration report
        //            repInfo.DateFrom = Utils.ParseDate(txtOTDDateStart.Text);
        //            repInfo.DateTill = Utils.ParseDate(txtOTDDateEnd.Text);

        //            if (ddlCriteria.SelectedItem.Value != "0")
        //            {
        //                repInfo.DateColumn = ddlCriteria.SelectedItem.Text;

        //                if (divDates.Visible == true)
        //                {
        //                    repInfo.DateFrom = Utils.ParseDate(txtDateStart.Text);
        //                    repInfo.DateTill = Utils.ParseDate(txtDateEnd.Text);
        //                }
        //                else if (divNumericValues.Visible == true && ddlExpr.SelectedItem.Value != "0" && txtValue.Text != "")
        //                {
        //                    repInfo.ExpressionText = ddlExpr.SelectedItem.Text;
        //                    repInfo.ExpressionValue = txtValue.Text;
        //                }
        //                else if (divExpression.Visible == true && txtLike.Text != "")
        //                {
        //                    repInfo.ExpressionLike = txtLike.Text;
        //                }
        //            }
        //            break;
        //        case 1004:  //Quantity Per Month
        //            if (ddlDateCriteriaField.SelectedValue != "0")
        //            {
        //                //repInfo.DateColumn = ddlWoByDateColumn.SelectedItem.Text;
        //                repInfo.SelectedOrganizationId = int.Parse(ddlOrgs.SelectedValue);
        //                repInfo.DateColumn = ddlDateCriteriaField.SelectedItem.Text;
        //                repInfo.DateFrom = Utils.ParseDate(txtOTDDateStart.Text);
        //                repInfo.DateTill = Utils.ParseDate(txtOTDDateEnd.Text);
        //            }
        //            break;
        //        case 1005:  //Inventory Balance
        //            if (ddlDateCriteriaField.SelectedValue != "0")
        //            {
        //                MLY.Bll.clsOrganization org = new MLY.Bll.clsOrganization(int.Parse(Session["OrganizationId"].ToString()));
        //                    repInfo.OrganizationId = (int)Session["OrganizationId"];
        //                    repInfo.SelectedOrganizationId = int.Parse(ddlOrgs.SelectedValue);
        //                repInfo.DateColumn = ddlDateCriteriaField.SelectedItem.Text;
        //                repInfo.DateFrom = Utils.ParseDate(txtOTDDateStart.Text);
        //                repInfo.DateTill = Utils.ParseDate(txtOTDDateEnd.Text);
        //            }
        //            break;
        //        case 1006:  //Graph Inventory Balance
        //            if (ddlDateCriteriaField.SelectedValue != "0")
        //            {
        //                MLY.Bll.clsOrganization org = new MLY.Bll.clsOrganization(int.Parse(Session["OrganizationId"].ToString()));
        //                if ((bool)org.Data.IsClient)
        //                {
        //                    repInfo.OrganizationId = (int)Session["OrganizationId"];
        //                    repInfo.SelectedOrganizationId = int.Parse(ddlOrgs.SelectedValue);
        //                }
        //                else
        //                {
        //                    repInfo.OrganizationId = int.Parse(ddlOrgs.SelectedValue);
        //                    repInfo.SelectedOrganizationId = (int)Session["OrganizationId"];
        //                }
        //                repInfo.DateColumn = ddlDateCriteriaField.SelectedItem.Text;
        //                repInfo.DateFrom = Utils.ParseDate(txtOTDDateStart.Text);
        //                repInfo.DateTill = Utils.ParseDate(txtOTDDateEnd.Text);
        //            }
        //            break;
        //        default:
        //            break;
        //    }
        //    //Session["advancedRptParamsReportInfo"] = repInfo;
        //    string repKey = MLY.Bll.ReportInfo.AddReportInfo(repInfo);

        //    string script = String.Format(@"<script language ='javascript'>window.open('reportsViewer.aspx?userRole={0}&repinfo={1}','a{2}','width=950, height=650,scrollbars=yes,resizable=yes,left=20,top=20')</script>",
        //                                    "Client", repKey, Guid.NewGuid().ToString("N"));
        //    this.ClientScript.RegisterStartupScript(this.GetType(), "myScript", script);


        //    //if (userRole == "Client")
        //    //{
        //    //    ClientsReports();
        //    //}
        //    //else if (userRole == "Contractor")
        //    //{
        //    //    ContractorsReports();
        //    //}

        //    //ShowReport();

        //}

        //protected void btnClose_OnClick(object sender, EventArgs e)
        //{
        //    //CrystalReportViewer1.ReportSource = null;
        //}

        //protected void ddlReports_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    //CrystalReportViewer1.ReportSource = null;
        //    if (Page.IsPostBack)
        //    {
        //        switch (ddlReports.SelectedIndex)
        //        {
        //            case 1:     // rptOnTimeDelivary
        //            case 4:     // monthly graph report
        //            case 5:     // InventoryBalance    
        //            case 6:     // GraphInventoryBalance
        //                LoadOrgs();
        //                break;
        //            default:
        //                // Do nothing
        //                break;
        //        }
        //    }
        //}

        //protected void ddlReports_PreRender(object sender, EventArgs e)
        //{
        //    //if (ddlReports.SelectedIndex == 1)//rptOnTimeDelivary
        //    //{
        //    //    LoadOrgs();
        //    //}
        //}

        //protected void ddlCriteria_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    divNumericValues.Visible = false;
        //    divDates.Visible = false;
        //    divExpression.Visible = false;

        //    int columnIdx = ddlCriteria.SelectedIndex;
        //    if (columnIdx >= 1 && columnIdx <= 4)
        //    {
        //        divDates.Visible = true;
        //    }
        //    else if (columnIdx >= 5 && columnIdx <= 9)
        //    {
        //        divNumericValues.Visible = true;
        //    }
        //    else if (columnIdx >= 10 && columnIdx <= 13)
        //    {
        //        divExpression.Visible = true;
        //    }
        //}

        //protected void ddlOrgs_Load(object sender, EventArgs e)
        //{

        //    //if (((ddlReports.SelectedIndex == 1) || (ddlReports.SelectedIndex == 4))
        //    //        && (!Page.IsPostBack))
        //    //{
        //    //    LoadOrgs();
        //    //}
        //    if (Page.IsPostBack)
        //    {
        //        switch (ddlReports.SelectedIndex)
        //        {
        //            case 1:     // rptOnTimeDelivary
        //            case 4:     // monthly graph report
        //            case 5:     // InventoryBalance    
        //            case 6:     // GraphInventoryBalance
        //                LoadOrgs();
        //                break;
        //            default:
        //                // Do nothing
        //                break;
        //        }
        //    }

        //}

        //protected void ddlOrgs_PreRender(object sender, EventArgs e)
        //{

        //    //if (ddlReports.SelectedIndex == 1)
        //    //{
        //    //    LoadOrgs();
        //    //}
        //}

        //protected void LoadOrgs()
        //{

        //    ddlOrgs.Items.Clear();
        //    MLY.Bll.clsOrganization org = new MLY.Bll.clsOrganization(int.Parse(Session["OrganizationId"].ToString()));

        //    bool IsClient = (bool)org.Data.IsClient;
        //    bool IsContractor = (bool)org.Data.IsContractor;
        //    //if (IsClient && IsContractor)
        //    //{
        //    //    ddlReports.SelectedIndex = 0;
        //    //    divOTD.Visible = false;
        //    //    lblErr.Visible = true;
        //    //}
        //    //else
        //    //{
        //    ddlOrgs.Items.Clear();
        //    ListItem all = new ListItem("All", "0");
        //    ddlOrgs.Items.Add(all);
        //    ddlOrgs.AppendDataBoundItems = true;

        //    if ((bool)org.Data.IsClient)
        //    {
        //        ddlOrgs.DataSource = MLY.Bll.clsOrganization.GetContractorsByClientId(org.Data.OrganizationId);
        //        ddlOrgs.DataBind();
        //    }
        //    else if ((bool)org.Data.IsContractor)
        //    {

        //        ddlOrgs.DataSource = MLY.Bll.clsOrganization.GetClientsByContractorId(org.Data.OrganizationId);
        //        ddlOrgs.DataBind();
        //    }
        //    //}


        //}



    }
}